package com.iversonx.decorator.example_1.service.v2.calculator;

import com.iversonx.decorator.TempDB;
import com.iversonx.decorator.example_1.service.v2.PrizeCalculator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;

public class GroupPrizeCalculator implements PrizeCalculator {
    private final Logger logger = LoggerFactory.getLogger(GroupPrizeCalculator.class);

    private final PrizeCalculator prizeCalculator;
    public GroupPrizeCalculator(PrizeCalculator prizeCalculator) {
        this.prizeCalculator = prizeCalculator;
    }
    @Override
    public BigDecimal calc(String user) {
        BigDecimal prize = prizeCalculator.calc(user);

        if(!isManger(user)) {
            return prize;
        }

        BigDecimal group = BigDecimal.ZERO;
        for(BigDecimal i : TempDB.MONTH_SALE_MONTY.values()) {
            group = group.add(i);
        }

        BigDecimal groupPrize = group.multiply(new BigDecimal("0.01"));
        logger.info("{}当月团队奖金:{}", user, groupPrize);
        return prize.add(groupPrize);

    }

    private boolean isManger(String user) {
        return TempDB.MANAGER_LIST.contains(user);
    }
}
